{% load i18n lfs_tags %}

<div class="navigation-pages-inline">
    {% if page.has_previous %}
        <a class="ajax-link"
           href="{% url lfs_manage_topseller_inline %}?page=1"><img src="{{ STATIC_URL }}icons/resultset_first.png" alt='{% trans "First" %}' /></a>
        <a class="ajax-link"
           href="{% url lfs_manage_topseller_inline %}?page={{ page.previous_page_number }}"><img src="{{ STATIC_URL }}icons/resultset_previous.png" alt='{% trans "Previous" %}' /></a>
    {% else %}
        <img src="{{ STATIC_URL }}icons/resultset_first.png" alt='{% trans "First" %}' />
        <img src="{{ STATIC_URL }}icons/resultset_previous.png" alt='{% trans "Previous" %}' />
    {% endif %}

    <span style="position: relative; top:-4px ">
        {{ page.number }} {% trans "of" %} {{ paginator.num_pages }}
    </span>

    {% if page.has_next %}
        <a class="ajax-link"
           href="{% url lfs_manage_topseller_inline %}?page={{ page.next_page_number }}"><img src="{{ STATIC_URL }}icons/resultset_next.png" alt='{% trans "Next" %}' /></a>
        <a class="ajax-link"
           href="{% url lfs_manage_topseller_inline %}?page={{ paginator.num_pages }}"><img src="{{ STATIC_URL }}icons/resultset_last.png"  alt='{% trans "Last" %}' /></a>
    {% else %}
        <img src="{{ STATIC_URL }}icons/resultset_next.png" alt='{% trans "Next" %}' />
        <img src="{{ STATIC_URL }}icons/resultset_last.png"  alt='{% trans "Last" %}' />
    {% endif %}
</div>
<table class="lfs-manage-table" style="margin-top:20px">
    <tr>
        <td width="50%">
            <h2>{% trans "Products" %}</h2>
            <form id="add-topseller-form"
                  action="{% url lfs_manage_add_topseller %}"
                  method="post">
                <div id="topseller-left" style="padding-bottom:10px">
                    <table class="lfs-manage-table">
                        <tr>
                            <th class="checkbox">
                                <input type="checkbox"
                                       class="select-all"
                                       value="products" />
                            </th>
                            <th>
                                {% trans 'Name' %}
                            </th>
                            <th class="small">
                                {% trans 'SKU' %}
                            </th>
                            <th class="tiny right-padding">
                                {% trans 'Active' %}
                            </th>
                        </tr>
                        {% for product in page.object_list %}
                            <tr class="{% cycle 'even' 'odd' %}">
                                <td>
                                    <input type="checkbox"
                                           name="product-{{ product.id }}"
                                           class="select-products" />
                                </td>
                                <td>
                                    <a href="{% url lfs_manage_product product.id %}">
                                        {{ product.get_name }}
                                    </a>
                                </td>
                                <td>
                                    {{ product.sku }}
                                </td>
                                <td class="right-padding">
                                    {% if product.is_active %}
                                        <img src="{{ STATIC_URL }}icons/tick.png" />
                                    {% else %}
                                        <img src="{{ STATIC_URL }}icons/cross.png" />
                                    {% endif %}
                                </td>
                            </tr>
                        {% endfor %}
                    </table>
                </div>
                <input type="hidden"
                       name="keep-filters"
                       value="1" />

                <input type="submit"
                       class="ajax-save-button button"
                       value="{% trans 'Add to topseller' %}" />

            </form>
        </td>
        <td width="50%">
            <h2>{% trans 'Topseller' %}</h2>
                <form id="topseller-update-form"
                      action="{% url lfs_manage_update_topseller %}"
                      method="post">
                    <div id="topseller-right" style="padding-bottom:10px">
                        <table class="lfs-manage-table">
                            <tr>
                                <th class="checkbox">
                                    <input type="checkbox"
                                           class="select-all"
                                           value="topseller" />
                                </th>
                                <th>
                                    {% trans 'Name' %}
                                </th>
                                <th class="small">
                                    {% trans 'SKU' %}
                                </th>
                                <th class="small">
                                    {% trans 'Position' %}
                                </th>
                                <th class="tiny right-padding">
                                    {% trans 'Active' %}
                                </th>
                            </tr>

                            {% for ts in topseller %}
                                <tr>
                                    <td>
                                        <input type="checkbox"
                                               name="product-{{ ts.id }}"
                                               class="select-topseller" />
                                    </td>
                                    <td>
                                        <a href="{% url lfs_manage_product ts.product.id %}">
                                            {{ ts.product.get_name }}
                                        </a>
                                    </td>
                                    <td>
                                        {{ ts.product.sku }}
                                    </td>
                                    <td>
                                        <input class="number"
                                               type="text"
                                               size="3"
                                               name="position-{{ ts.id }}"
                                               value="{{ ts.position }}" />
                                    </td>
                                    <td class="right-padding">
                                        {% if ts.product.is_active %}
                                            <img src="{{ STATIC_URL }}icons/tick.png" />
                                        {% else %}
                                            <img src="{{ STATIC_URL }}icons/cross.png" />
                                        {% endif %}
                                    </td>
                                </tr>
                            {% endfor %}
                        </table>
                    </div>
                    <input type="hidden"
                           name="keep-filters"
                           value="1" />

                    <input type="submit"
                           class="ajax-save-button button"
                           name="save"
                           value="{% trans 'Save topseller' %}" />

                    <input type="submit"
                           class="ajax-save-button button"
                           name="remove"
                           value="{% trans 'Remove from topseller' %}" />
                </form>
        </td>
    </tr>
</table>
<script>
    $("#manage-tabs").show();
    align_buttons("#topseller");
</script>
